//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"


// date -- 2017年04月05日19:47:48

/**控制流     */

//  for in

let names = ["Anna", "Alex", "Brian", "Jack"]
for name in names {
    print("Hello, \(name)!")
}

// for xx in 1..x
//这里不需要声明index的类型，就可以使用了。
for num in 1...5 {
    print("\(num) times 5 is \(num * 5)")
}


for index in 1...2 {
    print("\(index)+1 = \(index + 1)")
}

//如果不需要使用循环中的每一个值，我们可以用下划线符号来代替它。
let base = 3
let power = 10
var answer = 1
for _ in 1...power {
    answer *= base
}
print("\(base) to the power of \(power) is \(answer)")

//在某些情况下,您可能不希望使用封闭的范围,其中包括两个端点。考虑绘制每一分钟的刻度线手表的脸。你想画60刻度线,从0分钟。使用半开区间运算符(. . <)包括下界而不是上界。更多范围,见范围运算符。
let minutes = 60
for tickMark in 0..<minutes {
    //
}

//遍历 0 到 60 ，间隔为5 (半开区间，不包括60)
let minuteInterval = 5
for tickMark in stride(from: 0, to: minutes, by: minuteInterval) {
    print("\(tickMark)")
}

//遍历 0 到 60，间隔为5 (闭区间，包括60)
let minuteInterval2 = 5
for tickMark in stride(from: 0, through: minutes, by: minuteInterval2) {
    print("\(tickMark)")
}

//while loop
let finalSquare = 25
var board = [Int](repeatElement(0, count: finalSquare + 1))
board[03] = +08;
board[06] = +11;

//Conditional Statements

//if
var temperatureInFahrenheit = 30
if temperatureInFahrenheit <= 32 {
    print("It is very cold . Consider warning a scarf .")
}

temperatureInFahrenheit = 90
if temperatureInFahrenheit <= 32 {
    print("1")
}else if temperatureInFahrenheit >= 86 {
    print("2")
}else {
    print("3")
}

//switch
let someCharacter : Character = "z"
switch someCharacter {
case "a","b","z":
    print("z included")
default:
    print("some other character")
}

let approximateCount = 62
let countedThings = "moon orbiting Saturn"
let naturalCount : String
switch approximateCount {
case 0:
    naturalCount = "NO"
case 12 ..< 100:
    naturalCount = "dozens of"
default:
    naturalCount = "Many"
}

// functions  date :2017年04月07日18:07:21

func greeting(person:String) ->String{
    let greet = "see you again " + person + "!"
    return greet
}

print(greeting(person: "zhuzi"));


func greeting2() ->String{
    return "zhuzitongxue"
}
print(greeting2());

func greeting3(person:String  , alreadyGreeted:Bool) ->String{
    if alreadyGreeted{
        return greeting(person: person);
    }else{
        return greeting2();
    }
}
print(greeting3(person: "zhuzi", alreadyGreeted: true))


func minMax(array:[Int]) -> (min:Int ,max:Int){
    var currentMin = array[0]
    var currentMax = array[0]
    for value in array[1..<array.count]{
        if value < currentMin {
            currentMin = value
        }else if value > currentMax {
            currentMax = value
        }
    }
    return (currentMin,currentMax)
}
print(minMax(array: [1,2,3,4,9]))

//ab fix
